
-- $Id: LootFrame.lua 71 2009-04-06 04:43:41Z Fylgjas $

-- ========================================================================= --
-- Copyright © 2009 Thomas ROBERT (aka Fylgjas EU - Marécage de Zangar)      --
-- ========================================================================= --
-- This file is part of FyLooter.                                            --
--                                                                           --
-- FyLooter is free software: you can redistribute it and/or modify it under --
-- the terms of the GNU General Public License as published by the Free      --
-- Software Foundation, either version 3 of the License, or (at your option) --
-- any later version.                                                        --
--                                                                           --
-- FyLooter is distributed in the hope that it will be useful, but WITHOUT   --
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     --
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for  --
-- more details.                                                             --
--                                                                           --
-- You should have received a copy of the GNU General Public License along   --
-- with FyLooter. If not, see <http://www.gnu.org/licenses/>.                --
-- ========================================================================= --

local revision = tonumber(string.sub("$Rev: 71 $", 7, -3));

if (FyLooter.revision < revision) then
  FyLooter.revision = revision;
end

-- ========================================================================= --

-- 
-- _show_tooltip()
--
local function _show_tooltip(self)
  GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  GameTooltip:SetHyperlink(self:GetParent().item);
  GameTooltip:Show();
end

-- 
-- _hide_tooltip()
--
local function _hide_tooltip(self)
  GameTooltip:Hide();
end

-- ========================================================================= --

-- 
-- FyLooter:CreateLootFrame()
--
function FyLooter:CreateLootFrame(parent)
  -- LootFrame
  local LootFrame = CreateFrame("Frame", nil, parent);
  LootFrame:Hide();
  LootFrame:SetHeight(52);
  LootFrame:SetBackdrop(FyLooter.db.settings.backdrop);

  -- LootFrame.LootIcon
  local f = CreateFrame("Frame", nil, LootFrame);
  f:SetWidth(38);
  f:SetHeight(38);
  f:SetPoint("LEFT", 7, 0);
  f:EnableMouse(true);
  f:SetScript("OnEnter", _show_tooltip);
  f:SetScript("OnLeave", _hide_tooltip);

  LootFrame.LootIcon = f:CreateTexture(nil);
  LootFrame.LootIcon:SetAllPoints(f);

  -- LootFrame.LootLabel
  LootFrame.LootLabel = LootFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal");
  LootFrame.LootLabel:SetHeight(38);
  LootFrame.LootLabel:SetPoint("LEFT", lootIcon, "RIGHT", 7, 0);
  LootFrame.LootLabel:SetPoint("RIGHT", -7, 0);
  LootFrame.LootLabel:SetJustifyH("LEFT");

  -- 
  -- LootFrame:SetItem()
  --
  function LootFrame:SetItem(item)
    self.item = item;

    local name, _, quality, _, _, _, _, _, _, texture = GetItemInfo(item);
    local color = ITEM_QUALITY_COLORS[quality];

    self.LootIcon:SetTexture(texture);
    self.LootLabel:SetText(name);
    if (color) then
      self.LootLabel:SetTextColor(color.r, color.g, color.b);
    end
  end
  
  return LootFrame;
end

-- ========================================================================= --

